Prepare
library(tidyverse, warn.conflicts = F)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
library(purrr) # for functional programming
df <- read.csv("data/netflix_titles.csv", na.strings = c("", "NA"))
Grouping
by_country_type <- grouped %>% group_by(country, type) %>%
summarise(cnt = sum(cnt))
## `summarise()` has grouped output by 'country'. You can override using the
## `.groups` argument.
Movie Distribution by country
plot_ly(by_country_type %>% filter(type == "Movie"),
type = 'choropleth',
locations = ~country,
locationmode = 'country names',
z = ~cnt,
color = ~cnt,
colors = 'OrRd',
colorbar = list(title = 'Counts'),
text = ~paste(country, "<br>Counts: ", cnt)
)
TV Show Distribution by contry
plot_ly(by_country_type %>% filter(type == "TV Show"),
type = 'choropleth',
locations = ~country,
locationmode = 'country names',
z = ~cnt,
color = ~cnt,
colors = 'OrRd',
colorbar = list(title = 'Counts'),
text = ~paste(country, "<br>Counts: ", cnt)
)